/**
 * 
 */
package com.td.framework.webmanager.qxygns.action;

import java.util.List;

import com.td.framework.common.AbstractAction;
import com.td.framework.webmanager.domain.AppsysQxygns;
import com.td.framework.webmanager.domain.AppsysYmgnBean;
import com.td.framework.webmanager.login.UserInfo;
import com.td.framework.webmanager.qxygns.service.QxygnsService;
import com.opensymphony.xwork2.Action;

/**
 * 
 * Title:权限与功能树处理Action Description:处理权限与功能树 
 * Copyright: Copyright (c) 2008 
 * Company 北京水软科技有限公司
 * 
 * @author FLT006
 * @version 1.0
 */
public class QxygnsAction extends AbstractAction implements Action {

	private static final long serialVersionUID = 1L;
	private QxygnsService qxygnsService = null;// 权限与功能树业务接口;
	private List<AppsysQxygns> qxygnsList = null;// 权限与功能树List;
	private List<AppsysQxygns> treeList = null;// 生成功能树List;
	List<AppsysYmgnBean> ymgnBeanList = null;//页面功能List;
	private AppsysQxygns qxygns = null;// 权限与功能树对象;
	private String ymbh = "";// 页面编号;
	private String sjbh = "";// 上级页面编码;
	private String sjymmc = "";//上级页面名称;
	private String ymbhs = "";// 页面编号组,删除,修改用;
	private String[] pxh = null;//排序号;
	private String[] gnbhs = null;//功能编号;
	private String target = "";// 返回参数;
	private String urlFlag = "";// 判断路径;
	private String yhlx = "";//用户类型
	/**
	 * @toDo:生成权限与功能树列表;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String listQxygns() {
		
		qxygnsService.setSql(sjbh, qxygns);
		int rows = qxygnsService.getRows();
		page = this.pageService.getPage(rows, currentPage, pageSize, pageMethod);
		this.setCurrentPage(page.getCurentPage());
		this.setPageSize(page.getPageSize());
		qxygnsService.setSql(sjbh, qxygns);
		qxygnsList = qxygnsService.findBySjbh(page.getPageSize(), page.getStartRow());
		target = "list";
		return target;
	}

	/**
	 * @toDo:生成功能树;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String listQxygnsTree() {
		treeList = qxygnsService.getTreeList();
		target = "qxygnsTree";
		if(urlFlag.equals("init"))
		{
			target ="initQxygnsTree";
		}
		else if(urlFlag.equals("sel"))
		{
			target = "selQxygnsTree";
		}
		return target;
	}

	/**
	 * @toDo:查询权限与功能树信息;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String infoQxygns() {
		qxygns = qxygnsService.getAppsysQxygns(ymbh);
		sjymmc=qxygnsService.getAppsysQxygns(qxygns.getSjbh()).getYmmc();
		ymgnBeanList=qxygnsService.findAppsysYmgnBean(ymbh,4);
		target = "info";
		return target;
	}
	/**
	 * @toDo:生成主功能树;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String listMainTree()
	{
		String yhbh = "";
		if(this.getHttpsession().getAttribute("userInfo")!=null)
		{
			UserInfo userInfo = (UserInfo)this.getHttpsession().getAttribute("userInfo");
			yhbh=userInfo.getYhbh();
		}
		if(ymbh!=null&& ymbh.length()>0){
			treeList = qxygnsService.getMainTreeList(yhbh,ymbh);
		}else{
			treeList = qxygnsService.getMainTreeList(yhbh,"-1");
		}
		target = "mainTree";
		return target;		
	}
	/**
	 * @toDo:生成权限与功能树添加表单;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String createQxygnsForm() {
		qxygns = new AppsysQxygns();
		qxygns.setSjbh(sjbh);
		sjymmc=qxygnsService.getAppsysQxygns(sjbh).getYmmc();
		ymgnBeanList=qxygnsService.findAppsysYmgnBean("",3);
		target = "createForm";
		return target;
	}

	/**
	 * @toDo:保存权限与功能树
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String createQxygns() {
		if (qxygnsService.addAppsysQxygns(qxygns,gnbhs))
		{
			sjbh=qxygns.getSjbh();
			qxygns = new AppsysQxygns();
			qxygns.setSjbh(sjbh);
			this.handleMessage("info", "添加成功,请继续操作!");
			target = "addSuccess";
		}
		else
		{
			this.handleMessage("info", "添加失败,您添加的信息不符合要求,请重新添加!");
			target = "addFailure";
		}
		ymgnBeanList=qxygnsService.findAppsysYmgnBean("",3);
		sjymmc=qxygnsService.getAppsysQxygns(sjbh).getYmmc();
		return target;
	}

	/**
	 * @toDo:生成权限与功能树编辑表单;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String reworkQxygnsForm() {
		qxygns = this.qxygnsService.getAppsysQxygns(ymbhs.split(",")[0]);
		sjymmc=qxygnsService.getAppsysQxygns(qxygns.getSjbh()).getYmmc();
		ymgnBeanList=qxygnsService.findAppsysYmgnBean(ymbhs.split(",")[0],3);
		target = "reworkForm";
		return target;
	}

	/**
	 * @toDo:更新权限与功能树;
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String reworkQxygns() {
		String result ="";
		if (this.qxygnsService.updateAppsysQxygns(qxygns,gnbhs))
		{
			target = "updateSuccess";
			result ="OK";
		}
		else
		{
			target = "updateFailure";
			result ="failure";
			this.handleMessage("info", "修改失败,请重新修改!");
		}
		ymgnBeanList=qxygnsService.findAppsysYmgnBean(qxygns.getYmbh(),3);
		return target;
	}

	/**
	 * @toDo:删除权限与功能树;
	 * @return target;
	 */
	public String removeQxygns() {
		if (this.qxygnsService.deleteAppsysQxygns(ymbhs.split(",")))
		{
			target = "deleteSuccess";
		}
		else
		{
			target = "deleteFailure";
		}
		return target;
	}
	/**
	 * toDo:功能树初始化
	 * @return target;
	 */
	@SuppressWarnings("deprecation")
	public String initQxyGns()
	{
		String  path=this.getRequest().getRealPath("")+"\\initData";
		this.handleMessage("fileName", qxygnsService.initGns(ymbhs, path));
		target ="initQxyGns";
		return target;
	}
	/**
	 * toDo:权限与功能树排序列表
	 * @return target;
	 */
	@SuppressWarnings("unchecked")
	public String listOrderQxygns()
	{
		qxygnsService.setSql(sjbh, null);
		qxygnsList = qxygnsService.findBySjbh(1000000, 0);
		target = "orderQxygnsList";
		return target;
	}
	/**
	 * toDo:权限与功能树排序
	 * @return target;
	 */
	public String orderQxygns()
	{
		String result="";
		if(qxygnsService.orderQxygns(ymbhs.split(","), pxh))
		{
			result ="OK";
		}
		else
		{
			this.handleMessage("info", "排序失败,请重新操作!");
			result ="failure";
		}
		target = "orderQxygns";
		return target;
	}
	/**
	 * toDo:获取菜单树的下一层节点;
	 * @param sjbh
	 * @return list ;
	 */
	@SuppressWarnings("unchecked")
	public List<AppsysQxygns> getTreeItem(String yhbh,String sjbh)
	{
		treeList = qxygnsService.getMainTreeList(yhbh,sjbh);
		return treeList;
	}
	/**
	 * @toDo:get权限与功能树List ;
	 * @return the qxygnsList
	 */
	public List<AppsysQxygns> getQxygnsList() {
		return qxygnsList;
	}

	/**
	 * @toDo:set权限与功能树List ;
	 * @param qxygnsList
	 *            the qxygnsList to set
	 */
	public void setQxygnsList(List<AppsysQxygns> qxygnsList) {
		this.qxygnsList = qxygnsList;
	}

	/**
	 * @toDo:get生成功能树List ;
	 * @return the gnTreeList
	 */
	public List<AppsysQxygns> getTreeList() {
		return treeList;
	}

	/**
	 * @toDo:set生成功能树List ;
	 * @param gnTreeList
	 *            the gnTreeList to set
	 */
	public void setTreeList(List<AppsysQxygns> treeList) {
		this.treeList = treeList;
	}

	/**
	 * @toDo:get权限与功能树对象 ;
	 * @return the qxygns
	 */
	public AppsysQxygns getQxygns() {
		return qxygns;
	}

	/**
	 * @toDo:set权限与功能树对象 ;
	 * @param qxygns
	 *            the qxygns to set
	 */
	public void setQxygns(AppsysQxygns qxygns) {
		this.qxygns = qxygns;
	}

	/**
	 * @toDo:get上级页面编码 ;
	 * @return the sjbh
	 */
	public String getSjbh() {
		return sjbh;
	}

	/**
	 * @toDo:set上级页面编码 ;
	 * @param sjbh
	 *            the sjbh to set
	 */
	public void setSjbh(String sjbh) {
		this.sjbh = sjbh;
	}

	/**
	 * @toDo:get页面编号组 ;
	 * @return the ymbhs
	 */
	public String getYmbhs() {
		return ymbhs;
	}

	/**
	 * @toDo:set页面编号组 ;
	 * @param ymbhs
	 *            the ymbhs to set
	 */
	public void setYmbhs(String ymbhs) {
		this.ymbhs = ymbhs;
	}

	/**
	 * @toDo:get 权限与功能树业务接口;
	 * @return the qxygnsService
	 */
	public QxygnsService getQxygnsService() {
		return qxygnsService;
	}

	/**
	 * @toDo:set权限与功能树业务接口 ;
	 * @param qxygnsService
	 *            the qxygnsService to set
	 */
	public void setQxygnsService(QxygnsService qxygnsService) {
		this.qxygnsService = qxygnsService;
	}

	/**
	 * @toDo:get返回参数 ;
	 * @return the target
	 */
	public String getTarget() {
		return target;
	}

	/**
	 * @toDo:set返回参数 ;
	 * @param target
	 *            the target to set
	 */
	public void setTarget(String target) {
		this.target = target;
	}

	/**
	 * @toDo:get页面编号 ;
	 * @return the ymbh
	 */
	public String getYmbh() {
		return ymbh;
	}

	/**
	 * @toDo:set页面编号 ;
	 * @param ymbh
	 *            the ymbh to set
	 */
	public void setYmbh(String ymbh) {
		this.ymbh = ymbh;
	}
	/**
	 * @toDo:get判断路径 ;
	 * @return
	 */
	public String getUrlFlag() {
		return urlFlag;
	}

	/**
	 * @toDo:get判断路径 ;
	 * @param urlFlag 
	 */
	public void setUrlFlag(String urlFlag) {
		this.urlFlag = urlFlag;
	}

	/**
	 * toDo:get
	 * @return pxh
	 */
	public String[] getPxh() {
		return pxh;
	}

	/**
	 * toDo:set
	 * @param pxh 
	 */
	public void setPxh(String[] pxh) {
		this.pxh = pxh;
	}

	/**
	 * toDo:get
	 * @return sjymmc
	 */
	public String getSjymmc() {
		return sjymmc;
	}

	/**
	 * toDo:set
	 * @param sjymmc 
	 */
	public void setSjymmc(String sjymmc) {
		this.sjymmc = sjymmc;
	}

	/**
	 * toDo:get
	 * @return ymgnBeanList
	 */
	public List<AppsysYmgnBean> getYmgnBeanList() {
		return ymgnBeanList;
	}

	/**
	 * toDo:set
	 * @param ymgnBeanList 
	 */
	public void setYmgnBeanList(List<AppsysYmgnBean> ymgnBeanList) {
		this.ymgnBeanList = ymgnBeanList;
	}

	/**
	 * toDo:get
	 * @return gnbhs
	 */
	public String[] getGnbhs() {
		return gnbhs;
	}

	/**
	 * toDo:set
	 * @param gnbhs 
	 */
	public void setGnbhs(String[] gnbhs) {
		this.gnbhs = gnbhs;
	}

	/**
	 * @return the yhlx
	 */
	public String getYhlx() {
		return yhlx;
	}

	/**
	 * @param yhlx the yhlx to set
	 */
	public void setYhlx(String yhlx) {
		this.yhlx = yhlx;
	}
}
